﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Cn.Edwon.Web.Support;
using System.Reflection;
using Cn.Cellula.Model;
using Cn.Cellula.Biz.Port;
using Cn.Edwon.Spring;
using Cn.Edwon.Web.Validation;
using Cn.Edwon.Web;
using Cn.Cellula.Biz;
using Cn.Edwon.Biz;
using Cn.Cellula.Model.Content;
using Cn.Cellula.Client;

namespace Cn.Cellula.Website.Admin.Content.Comment {
    public partial class Edit : PageSupport {
        String EOKey = null;
        IBiz biz = BizFactory.Get<IBiz>();
        protected void Page_Load(object sender, EventArgs e) {
            EOKey = Request.QueryString["id"];
            if (!Page.IsPostBack) {
                InitForm();
                if (!String.IsNullOrEmpty(EOKey)) {
                    FillForm(EOKey);
                }
            }
        }

        void InitForm() {
        }
        void FillForm(String key) {
            VCommentEO eo = biz.Load<VCommentEO>(key, this.OwnerKey);
            this.txt_Content.Text = eo.Content;
            this.ddl_IsGood.SelectedValue = eo.IsGood.ToString();
            this.ddl_Score.SelectedValue = eo.Score+"";
        }

        protected void btn_save_Click(object sender, EventArgs e) {
            Boolean bk = QuickValidator.Execute(Request, this.ddl_IsGood.Parent);
            if (!bk) {
                SiteInfo.Send(Page, TxtDef.ERROR, QuickValidator.Message);
                return;
            }
            TCommentEO eo = biz.Load<TCommentEO>(EOKey, this.OwnerKey);
            eo.Content = this.txt_Content.Text;
            try {
                eo.IsGood = Convert.ToInt32(this.ddl_IsGood.SelectedValue);
            } catch {
            }

            try {
                eo.Score = Convert.ToInt32(this.ddl_Score.SelectedValue);
            } catch {
            }
            biz.Update<TCommentEO>(eo);
            BizFactory.Get<ILogBiz>().LogUpdate("评论", "", this.Actor, Request);
            Response.Redirect("List.aspx");
        }
    }
}
